#个人银行账户管理系统

#定义用于存放个人账户的列表变量
class UserBankOperation():

    userInfoList=[
        {"username":"Wang Lei","age":20,'userid':"001","balance":1200,"password":"123"},
        {"username": "Li Wen", "age": 30, 'userid': "002", "balance": 10000,"password":"123"},
        {"username": "Wang Hu", "age": 23, 'userid': "003", "balance": 1000,"password":"123"},
        {"username": "Yu Mei", "age": 18, 'userid': "004", "balance": 800,"password":"123"},
    ]
    
    def __init__(self,userId)
        self.userId=userId
        self.user=self.get_user_info()
    
    
    def get_user_info(self):
     for user in userInfoList:
            if(user["userid"]==self.userId):
                return user

    
    def showUserAccountInfo(self):
        for user in userInfoList:
            if(user["userid"]==self.userId):
                print("=" * 20, "用户信息查询结果", "=" * 21)
                print("|{0:<10}|{1:<10}|{2:<10}|".format("用户编号","姓名",  "账户余额"))
                print("|{0:<10}|{1:<10}|{2:<10}|".format( user["userid"], user["username"],user["balance"]))
                print("")
                return user

    def drawMoney(self,amount):
        if int(self.user["balance"])< int(amount):
            print("余额不足！")
            return
        else:
            user["balance"]=str(int(self.user["balance"])-int(amount))

            self.updateUserbalance(userInfoList,user)
            print("取款成功")
            print("您的当前余额是：", self.user['balance'])
            return

    def updateUserbalance(self):
            for index1,u in enumerate(userInfoList):
                if (u["userid"] == self.user["userid"]):
                        userInfoList[index]['balance'] = self.user['balance']
                        return
            print("用户信息不正确")
            print("")
            print("")


    def saveMoney(self,amount):
        self.user["balance"] = str(int(self.user["balance"]) + int(amount))
        updateUserbalance()
        print("存款成功")
        print("您的当前余额是：", self.user['balance'])
 
 def check_if_right_account(username,password)
    isLogin=False
    user_oper=None
    for user in UserBank.userInfoList:
                if user["username"] == username and user["password"] == password:
                    print("")
                    print("登入成功", "欢迎您", name)
                    user_oper=UserBankOperation(user["userid"])
                    isLogin = True
    return isLogin,user_oper
    
 

def main_func():
    while True:
        #输出登入页面
        print("="*20,"银行个人账户查询系统","="*20)
        print("")
        print("{0:<25}|{1:<25}".format("1，登入", "2，退出"))
        yourInput = input("请输入你的操作选项:")
        if yourInput == '1':
            print("-"*20,"请输入登入信息","-"*20)
            isLogin=False
            name =input("请输入用户名:")
            password =input("请输入密码:")
            for user in userInfoList:
                if user["username"] == name and user["password"] == password:
                    print("")
                    print("登入成功", "欢迎您", name)
                    isLogin = True
                    while True:
                        print("=" * 20, "银行个人账户管理系统", "=" * 20)
                        print("|{0:<25}|{1:<25}".format("1，查询", "2，取钱"))
                        print("|{0:<25}|{1:<25}".format("3，存钱", "4，退出"))
                        print("=" * 20, "选择你的操作序列号", "=" * 21)
                        yourChose = input("请输入你的操作选项:")
                        if yourChose == '1':
                            print("")
                            showUserAccountInfo(user["userid"])
                        elif yourChose == '2':
                            print("您的当前余额是：", user['balance'])
                            amount = input("请输入你要取款金额：")
                            drawMoney(user, amount)

                        elif yourChose == '3':
                            print("您的当前余额是：", user['balance'])
                            amount = input("请输入你要存款金额：")
                            saveMoney(user, amount)
                        elif yourChose == '4':
                            print("=" * 20, "再见", "=" * 33)
                            print("")
                            print("")

                            break
                        elif yourChose == '':
                            print("请输入操作序列号")
                            print("")
                        else:
                            print("没有这个选项，重新选择")
                            print("")

            if not isLogin:
                print("")
                print("用户信息错误，重新输入")
                print("")
        else:
            print("=" * 20, "再见", "=" * 33)
            print("")
            print("")
            break

if __main__=="__name__":
    main_func()







